{extend name="public/layout" /}
{block name="body"}
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <table id="admin-table" lay-filter="data-list"></table>
            </div>
        </div>
    </div>
{/block}
{block name="script"}
    <script src="/static/admin/js/action.js?v={$version}"></script>
    <script type="text/html" id="toolbar">
        <input class="layui-input table-input-text" id="search"  placeholder="用户搜索" value="">
        <a class="layui-btn" lay-event="search" >搜索</a>
        共有<span style="color: red">{$total}</span>人参加，其中有资格核销人数为<span style="color: red">{$zige}</span>,已核销人数为<span style="color: red">{$verify}</span>,有资格未核销人数为<span style="color: red">{$wait}</span>
    </script>
{literal}
    <script type="text/html" id="pic">
            <img style="display: inline-block;" width="20%" src={{ d.headimgurl }}>
    </script>
    <script type="text/html" id="row-handler">
        {{#  if(d.verify_auth == '是'){ }}
        <a  class="layui-btn" lay-event="detail">已是核销员</a>
        {{#  } else { }}
        <a onclick="set_verify_auth({{ d.id }})" class="layui-btn disabled" lay-event="detail">设为核销员</a>
        {{#  } }}
    </script>
{/literal}
    <script>
        function set_verify_auth(id){
            var url = '{:url('update')}';
            var d = new Object();
            d.id = id;
            d.verify_auth = 1;
            $.post(url,d,function(data){
                if(data.code == 10000){
                    layer.msg(data.msg,{
                        icon: 1,
                        time: 1000
                    },function(){
                        window.location.reload()
                    });
                }
            });
        };
        layui.use('table', function(){
            var table = layui.table;
            $ = layui.$;
            table.render({
                elem: '#admin-table'
                ,url: '{:url('index')}'
                ,page: true
                ,toolbar: '#toolbar'
                ,defaultToolbar:['filter']
                ,loading:true
                ,autoSort:false
                ,cols: [[
                    {field: 'id', title: 'ID',sort:true}
                    ,{field: 'nickname', title: '微信名'}
                    ,{field: 'headimgurl', title: '头像',templet:'#pic'}
                    ,{field: 'add_time', title: '参加时间'}
                    ,{field: 'verify_auth', title: '是否核销员'}
                    ,{field: 'verify', title: '是否已核销'}
                    ,{field: 'verify_time', title: '核销时间'}
                    ,{field: 'handler', title: '操作',toolbar:'#row-handler'}
                ]]
                ,parseData: function(res){
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.total,
                        "data": res.data.data
                    };
                }
                ,response: {
                    statusCode: 10000 //规定成功的状态码，默认：0
                }
            });



            //左上角按钮事件
            table.on('toolbar(data-list)', function(obj){
                switch(obj.event){
                    case 'search':
                        var key = $('#search').val();
                        table.reload('admin-table', {
                            url: '{:url('index')}'
                            ,where: {keyword: key}
                        });
                        break;
                };
            });

            //监听排序事件
            table.on('sort(data-list)', function(obj){
                table.reload('admin-table', {
                    initSort: obj
                    ,url: '{:url('index')}'
                    ,where: {'order': obj.field + ' ' + obj.type}
                });
            });
        });
    </script>
{/block}